import request from '@/utils/request'
import { encryptedData } from '@/utils/encrypt'
import { loginRSA } from '@/config'

export async function login (data) {
  if (loginRSA) {
    data = await encryptedData(data)
  }
  return request({
    url: '/api/UserApi/Login/Login',
    method: 'post',
    data,
  })
}

export async function loginByOfficialAccountsCode ({ code, officialAccountId }) {
  return request({
    url: '/api/Login/LoginByOfficialAccountsCode',
    method: 'post',
    data: { code, officialAccountId },
  })
}

export function getUserInfo (data) {
  return request({
    url: '/api/UserApi/Login/GetUserInfo',
    method: 'post',
    data,
  })
}

export function logout () {
  return request({
    url: '/api/UserApi/Login/Logout',
    method: 'post',
  })
}

export function register () {
  return request({
    url: '/register',
    method: 'post',
  })
}
